/*******************************************************************************
*  Project      : Minigate Golfin                                 
*  Program ID   : pop_pw.js                                 
*  Description  : 비밀번호 입력
*
********************************************************************************
*  Program History                                                            
*  Date        Author    Description                                          
*  ----------  --------  -------------------------------------------------------- 
*  2012-06-19  김효순    Created.  
*  2012-04-19  김효순    Finished.  
*******************************************************************************/

jQuery(function($){
	function clsPasswd()
	{
		this._HTMLDom = null;
		this._ERRMSG = {
			"_NOVALUE": "비밀번호를 입력해 주십시요."
		}
		this.errMsg = null;
		
		this._init();
	}
	
	clsPasswd.prototype = {
		_init: function(){
			var $layer = $("input:password");
			this._HTMLDom = {
				"$layer": $layer
			}
			
			this.reset();
		}
		, reset: function(){
			return this._HTMLDom["$layer"].val("");
		}
		, getError: function(){
			if(this.errMsg) return this._ERRMSG[this.errMsg];
			else return null;
		}
		, valid: function(){
			var val = this._HTMLDom["$layer"].val();
			
			if(!val){
				this.errMsg = "_NOVALUE";
				return false;
			}
			
			return true;
		}
		, focus: function(){
			this._HTMLDom["$layer"].trigger("focus");
		}
		, getValue: function(){
			return this._HTMLDom["$layer"].val();
		}
		, $getTextBox: function(){
			return this._HTMLDom["$layer"];
		}
		
	}
	
	function clsTabView()
	{
		this._arrLayer = null;
		
		this.idx = null;
		
		this._init();
	}
	
	clsTabView.prototype = {
		_init: function(){
			this._arrLayer = [
				$("div.pw_area"), $("div.pw_area01")
			];
			
			this.setIdx(0);
		}
		, setIdx: function(n){
			this.idx = n;
			this.display();
		}
		, display: function(){
			$(this._arrLayer).each(function(){
				this.hide();
			});
			
			this._arrLayer[this.idx].show();
			document.objUtil.setWindowSize();
		}
	}
	
	function clsComm()
	{
	
	}
	
	clsComm.prototype = {
		
	}
	
	function clsControl()
	{
		this.objComm = null;
		this.objPasswd = null;
		this.objTabView = null;
		
		this.passwd = null;
	}
	
	clsControl.prototype = {
		_init: function(){
			if(!(opener && opener.document && opener.document.objControl)) self.close();
			
			this.passwd = opener.document.objControl.getPasswd();
			
			//this.passwd = "1234";
			
			this.objComm = new clsComm();
			this.objPasswd = new clsPasswd();
			this.objTabView = new clsTabView();
			
			this._bind();
		}
		, _bind: function(){
			var thisClass = this;
			
			// 닫기
			$("img[alt='close']").click(function(){
				self.close();
			});
			
			// 비밀번호 확인
			$("input:image").click(function(){
				if(!thisClass.objPasswd.valid()){
					alert(thisClass.objPasswd.getError());
					thisClass.objPasswd.focus();
					return;
				}
				
				if(thisClass.passwd == thisClass.objPasswd.getValue()){
					opener.document.objControl.goViewPage(self);
				}else{
					thisClass.objPasswd.reset();
					thisClass.objTabView.setIdx(1);
				}
			});
			
			// 재입력 확인
			$("img[alt='확인']").click(function(){
				thisClass.objTabView.setIdx(0);
			});
			
			// 엔터체크
			this.objPasswd.$getTextBox().keydown(function(event){
				if(event.keyCode == 13) $("input:image").trigger("click");
			});
		}
	}
	
	document.objControl = new clsControl();
	document.objControl._init();
});